<?php
namespace app\sports\match\controller;

use app\sports\match\service\JCService;
use think\Controller;

/**
 * 竞彩
 * Class JingCai
 * @package app\sports\match\controller
 */
class JC extends Controller
{
    /**
     * 获取竞彩列表
     */
    public function getJCList()
    {
        $post = $this->request->post();
        $type = isset($post['type']) ? $post['type'] : '';
        $page = isset($post['page']) ? $post['page'] : 1;
        $count = isset($post['count']) ? $post['count'] : 10;
        $service = new JCService();
        $data = $service->getJCList($type, $page, $count);

        if ($data['code'] != 0) {
            $this->jsonReturn($data['code'], [], $data['msg']);
        }

        $this->jsonReturn(0, $data['data']);
    }

    /**
     * 获取竞彩单场比赛
     */
    public function getJCSimpleByMatchId()
    {
        $post = $this->request->post();
        $matchId = isset($post['matchId']) ? $post['matchId'] : 0;
        $type = isset($post['type']) ? $post['type'] : '';

        if (empty($matchId)) {
            $this->jsonReturn(-1, [], '比赛ID不能为空');
        }

        $service = new JCService();
        $data = $service->getJingCaiSimpleByMatchId($type, $matchId);

        if ($data['code'] != 0) {
            $this->jsonReturn($data['code'], [], $data['msg']);
        }

        $this->jsonReturn(0, $data['data']);
    }

    /**
     * 获取竞彩多场比赛
     */
    public function getJcListByMatchId()
    {
        $post = $this->request->post();
        $matchId = isset($post['matchId']) ? $post['matchId'] : 0;
        $type = isset($post['type']) ? $post['type'] : '';

        if (empty($matchId) || !is_array($matchId)) {
            $this->jsonReturn(-1, [], '比赛信息有误');
        }

        $service = new JCService();
        $data = $service->getJcListByMatchId($type, $matchId);

        if ($data['code'] != 0) {
            $this->jsonReturn($data['code'], [], $data['msg']);
        }

        $this->jsonReturn(0, $data['data']);
    }
}